package utils;

import java.lang.reflect.Field;

import play.Play;
import play.jobs.Job;
import play.jobs.OnApplicationStart;

@SuppressWarnings("rawtypes")
@OnApplicationStart
public final class SystemParam extends Job {
	/**
	 * 同步时分页的大小
	 */
	public static int RECORDCOUNT = 5;
	
	/**
	 * 异步调用时的休眠时间
	 */
	public static int AWAITTIME = 1000;

	/**
	 * 请求超时时间
	 */
	public static int HTTP_TIMEOUT = 6000;

	/**
	 * 允许同时发送的最大请求总数
	 */
	public static int HTTP_MAXSIZE = 50;
	
	/**
	 * 向kafka发消息时的缓存记录数
	 */
	public static int KAFKA_BUFFERSIZE = 100;

	/**
	 * 向kafka发消息时的缓存时间
	 */
	public static int KAFKA_TIMEOUT = 6000;

	/** 业务消息主题 */
	public static enum Topic {
		/**锁座*/
		Lock,
		/**解锁*/
		Unlock,
		/**售票*/
		SellTicket,
		/**售票第三态*/
		SellUnknown,
		/**退票*/
		RefundTicket,
		/**退票第三态*/
		RefundUnknown,
		/**特权退票 */
		SpecialReturnticket,
		/**特权退票第三态 */
		SpecialReturnUnknown,
		/**错误消息*/
		ErrorConsumer,
		/**锁座*/
		Lock_gansutest,
		/**解锁*/
		Unlock_gansutest,
		/**售票*/
		SellTicket_gansutest,
		/**售票第三态*/
		SellUnknown_gansutest,
		/**退票*/
		RefundTicket_gansutest,
		/**退票第三态*/
		RefundUnknown_gansutest,
		/**特权退票 */
		SpecialReturnticket_gansutest,
		/**特权退票第三态 */
		SpecialReturnUnknown_gansutest,
		/**错误消息*/
		ErrorConsumer_gansutest;
	}

	/**
	 * 用来控制httpsize的标记
	 */
	public static enum HttpMark {
		receive,
		send
	}
	
	public SystemParam() {
		for (Field f : this.getClass().getFields()) {
			if (f.getModifiers() == 25) {
				continue;
			}
			Object o = Play.configuration.getProperty(f.getName());
			if (o != null) {
				Object value = o;
				if (f.getType().getName().equals("int")) {
					value = Integer.parseInt(o.toString());
				} else if (f.getType().getName().equals("Long")) {
					value = Long.parseLong(o.toString());
				} else if (f.getType().getName().equals("float")) {
					value = Float.parseFloat(o.toString());
				} else if (f.getType().getName().equals("boolean")) {
					if ("1".equals(o.toString())) {
						value = true;
					} else {
						value = Boolean.parseBoolean(o.toString());
					}

				}
				try {
					f.set(this, value);
				} catch (Exception e1) {
				}
			}
		}
	}
}
